<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\bootstrap\Modal;
/* @var $this yii\web\View */
/* @var $searchModel app\models\WmProductSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t('app', 'Wm Products');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="wm-product-index">
    <?php

    Modal::begin([
        'header' => '<h2>Hello world</h2>',
    ]);
    echo 'Say hello...';
    Modal::end();
    ?>

    <p>
        <?php
        echo Html::a(Yii::t('app', 'back'), ['user/index'], ['class' => 'btn btn-success'])
        ?>
    </p>

    <?php  echo $this->render('_search', ['model' => $searchModel]); ?>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
//        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

//            'id',
//            'uid',
//            'product_name',
            [
                'attribute' => 'product_name',
                'format' => 'raw',
                'value' =>
                    function ($data) {
                        return html::a($data->product_name,['active/index','WmActiveSearch[pid]'=>$data->id],['title' => '审核']);
                    },
            ],
            'package_name',
            'activeCount',
            [
                'attribute' => 'created_at',
                'visible' => Yii::$app->user->identity->is_admin == 1,
                'value' => function ($data) {
                    return date("Y-m-d H:i:s",$data['created_at']);
                },
            ],

            ['class' => 'yii\grid\ActionColumn',
                'header' => '操作',
                'options' => ['width' => '100px;'],
                'template' => '{update}{active}{modal}',
                'visible'=>Yii::$app->user->identity->is_admin==1,
                'buttons' => [

                    'active' => function ($url, $model) {
                        return Html::a('<span class="">' . Yii::t('app', 'Create Wm Active') . '</span>', ['active/create', 'pid' => $model->id,'ajax'=>1], [
                            'class' => 'glyphicon','data-toggle'=>'modal','data-target'=>'#ajax'.$model->id

                        ]);

                    },
                    'update' => function ($url, $model) {
                        return Html::a('<span class="">' . Yii::t('app', 'Update') . '</span>', ['product/update', 'id' => $model->id,'ajax'=>1], [
                            'class' => 'glyphicon','data-toggle'=>'modal','data-target'=>'#ajax_'.$model->id

                        ]);

                    },
                    'delete' => function ($url, $model) {
                        return Html::a('<span class="">'.Yii::t('app', 'Delete').'</span>', ['delete', 'id' => $model->id], [
                            'class' => 'glyphicon',
                            'data' => [
                                'confirm' => Yii::t('app', 'Are you sure you want to delete this project?'),
                                'method' => 'post',
                            ], ]);

                    },
                    'modal' => function ($url, $model) {
                        return '<div class="modal fade" id="ajax' . $model->id . '">
                                    <div class="modal-dialog">
                                        <div class="modal-content">

                                        </div>
                                    </div>
                                </div><div class="modal fade" id="ajax_' . $model->id . '">
                                    <div class="modal-dialog">
                                        <div class="modal-content">

                                        </div>
                                    </div>
                                </div>';
                    }


                ],



            ],
        ],
    ]); ?>
</div>
